package cn.fighter3.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.fighter3.entity.ShopUser;
import cn.fighter3.entity.User;
import cn.fighter3.result.CommonResult;
import cn.fighter3.service.IShopUserService;
import cn.fighter3.util.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 林阔
 * @since 2023-08-26
 */
@RestController
@RequestMapping("/shopUser")
public class ShopUserController {

    @Autowired
    private IShopUserService shopUserService;

    @PostMapping("/user/add")
    @ApiOperation(value = "添加用户接口")
    public CommonResult addUser(@RequestBody ShopUser shopUser) {
        this.shopUserService.save(shopUser);
        return CommonResult.ok();
    }

    @GetMapping("/user/get-by-id")
    @ApiOperation(value = "根据id获取用户信息接口")
    public CommonResult getUserById(@RequestParam Integer id) {
        ShopUser shopUser = this.shopUserService.getById(id);
        User user = SecurityUtils.getUser();
        System.out.println(user.getUserName());
        return CommonResult.ok(shopUser);
    }
}
